<template>
  <div class="tab-container">
    <!-- Tab 标签栏 -->
    <div class="tab-header">
      <div
        v-for="(tab, index) in allTabs"
        :key="index"
        class="tab-item"
        :class="{ 'active': activeTab === tab.id }"
        @click="changeTab(tab.id)"
      >
        {{ tab.title }}
      </div>
    </div>

    <!-- Tab 内容区域 -->
    <div class="tab-content">
      <div
        v-for="(tab, index) in allTabs"
        :key="index"
        v-show="activeTab == tab.id"
        class="tab-pane"
      >
        <div class="list">
          <ul>
            <li v-for="(item,index) in itemList" :key="item.id" @click="gotoDetail(item)" class="hand-cursor">
              <img
                :src="item.cover"
              >
              <div class="name">{{ item.title }}</div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { listShuangshi } from '@/api/teach/shuangshi/shuangshi'
import { listCourse } from '@/api/teach/course/course'
import { listMaterial } from '@/api/teach/course/material'

export default {
  name: 'TabTeachComponent',
  data() {
    return {
      activeTab: 'tab1',
      allTabs: [
        { id: 'tab1', title: '双师书法课堂', content: '这是选项1的内容' },
        { id: 'tab2', title: '名师课堂', content: '这是选项2的内容' },
        { id: 'tab3', title: '教学课件', content: '这是选项3的内容' }
      ]
      ,
      total: 0,
      itemList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 8
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    changeTab(tabId) {
      this.activeTab = tabId
      this.getList()
    },
    getList() {
      this.loading = true
      if (this.activeTab === 'tab1') {
        listShuangshi(this.queryParams).then(response => {
          this.itemList = response.rows
          this.total = response.total
        })
      } else if (this.activeTab === 'tab2') {
        listCourse(this.queryParams).then(response => {
          this.itemList = response.rows
          this.total = response.total
        })
      } else {
        listMaterial(this.queryParams).then(response => {
          this.itemList = response.rows
          this.total = response.total
        })
      }

      this.loading = false
    },

    gotoDetail(item) {
      var routeData=null
      if (this.activeTab === 'tab1') {
          routeData = this.$router.resolve({
          path: '/shuangShiDetail',
          query: { id: item.id } // 保持原有的 query 传参
        });
      }else if (this.activeTab === 'tab2'){
        routeData = this.$router.resolve({
          path: '/courseDetail',
          query: { id: item.id } // 保持原有的 query 传参
        });
      }else {
        window.open(item.fileUrl, '_blank');
        return
      }
      window.open(routeData.href, '_blank');
    }

  }

}
</script>

<style lang="scss" scoped>
.tab-container {
  font-family: Arial, sans-serif;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.tab-header {
  display: flex;
  border-bottom: 1px solid #ddd;
  position: relative;
}

.tab-item {
  padding: 10px 20px;
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
  margin-right: 5px;
  position: relative;
  color: #a77e30;;
}

.tab-item:hover {
  background-color: #f5f5f5;
}

.tab-item.active {
  border-color: #ddd;
  border-bottom-color: #fff;
  background-color: #fff;
  border-radius: 5px 5px 0 0;
  margin-bottom: -1px;
  font-weight: bold;
}


.tab-content {
  padding: 20px;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 5px 5px;
  min-height: 200px;
}


.tab-pane.active {
  display: block;
}

.list {
  ul {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  li {
    width: 23%;
    margin-top: 10px;
    margin-bottom: 10px;

    img {
      width: 270px;
      height: 180px;
      object-fit: cover;
      border-radius: 10px;
    }

    .name {
      width: 270px;
      font-size: 18px;
      color: #ffffff;
      height: 25px;
      background-color: #a77e30;
      text-align: center;
      border-radius: 5px;
    }
  }
}

.hand-cursor {
  cursor: pointer; /* 核心属性 */
  /* 其他样式（可选） */
  color: #42b983;
  padding: 8px;
}
</style>
